require(['loading'], function(loading) {
	// 获取上页面参数键值
	var params = getUrlParams(); 
	var category1 = params.category1?params.category1:"";
	var type = params.type;

	var pageNo = 1;
	var level = 1;
	var topClass2 = '分类';
	//应用实例化
	var allFarm = new Vue({
		el: '#allFarm',
		data: {
			goodsList: [],
			provinceData:[],
			classData: [],
			showLoading: false,
			isProv: false,
			noData: false,
			apiUrl: wxUrl + '/v3.2/large/list',
			areaUrl: wxUrl + '/v3.2/addr/areaList',
			classUrl: wxUrl + '/v3.2/goodsClass/findSonGoodsClass',
			item: {
				params:{
					token: token,
					userToken: userToken,
					lng: longitude,
					lat: latitude,
					pageNo : pageNo,
					pageSize : 20,
					type: type,
					firstAddressId: '',
					secondAddressId: '',
					category1: category1,
					category2: '',
					category3: ''
				}
			},
			areaItem: {
				params:{
					token: token,
					parentAreaId: ''
				}
			},
			classItem: {
				params:{
					token: token,
					parentId: ''
				}
			}
		},
		methods: {
			moreFn: function() {
				this.$http.get(this.apiUrl, this.item)
				.then(function(response) {
					var result = JSON.parse(response.body);
					if (result.code == 0) {
						var goodsData = result.data.list;
						this.goodsList = this.goodsList.concat(goodsData);
						if(goodsData.length == 0 && this.item.params.pageNo == 1){
							this.noData = true;
						}else{
							this.noData = false;
						}						
					}
				});
			},
			getMore: function() {
				var contiueFlag = this.goodsList.length < this.item.params.pageNo * 20;
				if (contiueFlag) { // 如果没有更多数据，则不调用远程
					promptBox('没有更多数据了！');
					return;
				}
				this.item.params.pageNo++;
				this.moreFn();
			},
			init: function() {
				this.moreFn();
			}
		}
	});
	allFarm.init(); //pageNo=1
	
	//切换tap
	$(function(){
		$(".tap li").click(function(){
			$(".tap li").removeClass('active');
			$(this).addClass('active');
			var index = $(this).index();
			$('.countent ul').removeClass('show');
			$('.countent ul').eq(index).addClass('show')
		});
	});
});
// 为可控制返回指定页面所有添加pushState
history.pushState({}, document.title, null);
pushVHistory();
window.addEventListener("popstate", function() {
    // 跳转到订单列表页面
	goBackVHistory();
});